<?php
namespace app\common\base;

use Yii;
use yii\web\Controller;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/10/30 0030
 * Time: 15:43
 */
class BaseController extends Controller
{
    public $layout='bootcss';
    public $enableCsrfValidation=false;

    public function init()
    {
        parent::init();
        if(!Yii::$app->session->isActive) {
            Yii::$app->session->open();
        }
        if(!Yii::$app->session->has('regname')) {
            $this->redirect('/');
        }
    }

    public function getParam($name, $def = null) {
        if(Yii::$app->request->isGet) {
            return Yii::$app->request->get($name, $def);
        }
        return Yii::$app->request->post($name, $def);
    }

    public function out($status, $msg = null, $data = null) {
        return json_encode([
            'status' => $status,
            'msg' => $msg,
            'data' => $data
        ]);
    }

}